package com.itheima.dao;

import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.Date;
import java.util.List;
import java.util.Map;

public interface ReportDao {
    @Select("SELECT count(id) FROM t_member WHERE regTime<=#{time}")
    Integer findByTime(String time);

    @Select("SELECT s.`name`,COUNT(*) value FROM t_order o,t_setmeal s WHERE o.`setmeal_id` = s.`id` GROUP BY o.`setmeal_id`")
    List<Map<String, Object>> findsetmealCount();

    @Select("select count(*) from t_member where regTime = #{today}")
    Integer findTodayNewMember(String today);

    @Select("select count(*) from t_member")
    Integer findTotalMember();

    @Select("select count(*) from t_member where regTime>=#{thisWeekNewMember}")
    Integer findThisWeekNewMember(String thisWeekMonday);


    @Select("select count(*) from t_order where orderDate = #{date}")
    Integer findTodayOrderNumber(String today);

    @Select("select count(*) from t_order where orderDate = #{date} and orderStatus = '已到诊'")
    Integer findTodayVisitsNumber(String today);

    @Select("select count(*) from t_order where orderDate >= #{date}")
    Integer findThisWeekOrderNumber(String mondy);

    @Select("select count(*) from t_order where orderDate >=#{date} and orderStatus = '已到诊'")
    Integer findThisWeekVisitsNumber(String mondy);

    @Select("SELECT s.`name`,COUNT(o.`setmeal_id`) setmeal_count,COUNT(o.`setmeal_id`)/(SELECT SUM(tt.id) FROM (SELECT COUNT(*) id  FROM t_order GROUP BY setmeal_id ORDER BY id DESC LIMIT 0,5) tt) proportion FROM t_order o,t_setmeal s WHERE o.`setmeal_id` = s.`id` GROUP BY o.setmeal_id ORDER BY setmeal_count DESC limit 0,5")
    List<Map<String, Object>> findHotSetmeal();

    List<Date> getOrder(@Param("beginDate") String beginDate, @Param("endDate") String endDate);

    @Select("select count(*) from t_order where orderDate = #{date}")
    Integer getReport(Date date);
    @Select("select count(*) from t_order where orderDate = #{date} and orderStatus = '已到诊'")
    Integer findStatus(Date date);

    //@Select("select setmeal_id from t_order where")
    List<Integer> findSetmealId(@Param("beginDate") String beginDate, @Param("endDate") String endDate);

    @Select("select count(*) from t_order where setmeal_id = #{id}")
    Integer findCount(Integer id);

    @Select("select price,name from t_setmeal where id = #{id}")
    Map<String, String> findById(Integer id);

    @Select("select name from t_setmeal where id = #{id}")
    String findNameById(Integer id);

    @Select("select price from t_setmeal where id = #{id}")
    String findPriceById(Integer id);

    @Select("select count(*) from t_member where sex = #{sex}")
    Integer findSex(int sex);

    @Select("select count(*) from t_member where sex = #{i}")
    Integer findSexNv(int i);
}
